package xyz.scootaloo.draft.socket;

import java.io.*;
import java.net.Socket;

/**
 * @author flutterdash@qq.com
 * @since 2021/5/12 9:29
 */
public class Client {

    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1", Server.port);
            //构建IO
            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            //向服务器端发送一条消息
            bw.write("测试客户端和服务器通信，222服务器接收到消息返回到客户端\n");
            bw.flush();

            //读取服务器返回的消息
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String mess = br.readLine();
            System.out.println("服务器:"+mess);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
